<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="../../js/jquery-3.1.0.min.js"></script>
<title>Insert title here</title>
<script>
var currentpage =${currentpage} ;
var totalpage =${totalpage};
$(document).ready(function(){
	$("#firest").click(function(){
		currentpage=1;
		getList();
	})
	$("#up").click(function(){
		if(currentpage==1){
			alert("当前已经为第一页了");
		}else{
			currentpage--;
			getList();
		}
	});
	$("#down").click(function(){
		if(currentpage==totalpage){
			alert("当前页已经是最后一页");
		}else{
			currentpage++;
			getList();
		}
	});
		$("#end").click(function(){
			currentpage=totalpage;
			getList();
		})
		$(".add").click(function(){
			location.href="GetListGoodsTypeServlet";
		})
		$(".search").click(function(){
			alert($("#keyname").val());
			currentpage=1;
			getList();
		})
		$(".del").click(function(){
										var id = $(this).parents("td").prevAll(".id").html();
										if(confirm("是否确定删除")){
											location.href="delGoodsTypeServlet?gtypeid="+id+"&currentpage="+currentpage;
										}
									});
		$(".add").click(function(){
			location.href="addgoodstype.jsp";
		})
		 $(".update").click(function(){
									  location.href ="addgoodstype.jsp?gName="+$(this).parents("td").prevAll(".gtypename").html()+"&id="+$(this).parents("td").prevAll(".id").html();
									})
		function getList(){
			location.href="GetListGoodsType?currentpage="+currentpage+"&keyname="+$("#keyname").val();
		}
})
</script>
</head>
<body>
商品名称：<input type="text" id="keyname" >
<input type="button" value="搜索" class="search">
<input type="button" value="添加" class="add">
	<table border="1" class="goods">
		<tr>
			<th>商品类型id</th>
			<th>商品类型名称</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${list}" var ="gtype">
		<tr>
		<td class="id">${gtype.goodstype_id}</td>
		<td class="gtypename">${gtype.goodstype_name}</td>
		<td>
				<input type="button" value="删除" class="del" >
				<input type="button" value="修改"  class="update">
			</td>
		</tr>
		</c:forEach>
	</table>
	<input type="button" value="第一页" id= "firest">
	<input type="button" value="上一页" id ="up">
	<input type="button" value="下一页" id = "down">
	<input type="button" value="最后一页" id = "end">
	${currentpage}/${totalpage}
</body>
</html>